import _thread
import time


def print_thread(lock,name,time=20):
    for i in range(0,time):
        with lock:
            print("name[%s]time[%d]." % (name,i))



def test():
    lock=_thread.allocate_lock()
    _thread.start_new_thread(print_thread,(lock,'th1',30))
    _thread.start_new_thread(print_thread,(lock,'th2',30))
    _thread.start_new_thread(print_thread,(lock,'th3',30))